"""
Demonstrates how to use the BudgetCategory class to find the children of
the requested category

Todo: Calculate yearly totals for each child category
"""

import locale
from models import BudgetCategory


locale.setlocale(locale.LC_ALL, "") #Used to format numbers with commas for thousands

urls = [
    "Department_of_Energy",
    "Department_of_Energy/National_Nuclear_Security_Administration",
    "Department_of_Energy/National_Nuclear_Security_Administration/Weapons_Activities",
    "Department_of_Energy/National_Nuclear_Security_Administration/Weapons_Activities/Atomic_energy_defense_activities"    
    ]


print "Drilling into details fo Category:"

for url in urls:
    print "Detail for: ", url
    print "-----------------------------------------------------"
    
    budget = BudgetCategory(url)
   
    for childCategory in budget.children():
        print childCategory
            


print "\n\nDisplaying totals for a single subcategory of level 2"
print "   (note: this is currently hard-coded for only this level)"

url =  "Department_of_Energy/National_Nuclear_Security_Administration"

print "\nCategory:", url

budget2 = BudgetCategory(url,1999, 2008)

print "\n--- Yearly Totals ---"
for year, amount in budget2.yearTotals().iteritems():
    print year,  "  ", locale.format('%d', amount, True)

print "\n--- Child Categories ---"
for childCategory in budget2.children():
    print childCategory

print "\n\n"
